<template>
	<globalModal :title="title" :visible="visible" :confirmLoading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
		<a-spin :spinning="confirmLoading">
			<a-form :form="form" autocomplete="off" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<a-form-item label="所属机构" v-if="isAdmin">
					<a-select allowClear :disabled="!isAdd" v-decorator="['orgId', { rules: [{ required: isAdmin, message: '所属机构' }] }]" placeholder="所属机构">
						<a-select-option :value="item.orgId" v-for="(item, index) in orgList" :key="index">{{ item.orgName }}</a-select-option>
					</a-select>
				</a-form-item>
				<a-form-item label="角色名">
					<a-input
						placeholder="角色名"
						v-decorator="[
							'roleName',
							{ rules: [{ required: true, message: '角色名' }, { max: 50, message: '角色名不超过50个字符' }], getValueFromEvent: removeSpaces }
						]"
					/>
				</a-form-item>
				<a-form-item label="角色编码" extra="长度为4~50位, 必须包含数字、字母、符号( - 或 _ )中至少一种">
					<a-input
						placeholder="角色编码"
						:disabled="!isAdd"
						v-decorator="[
							'roleCode',
							{
								rules: [{ required: true, message: '角色编码' }, { pattern: /^[0-9a-zA-Z-_]{4,50}$/, message: '长度为4~50位, 必须包含数字、字母、符号( - 或 _ )中至少一种' }],
								getValueFromEvent: removeSpaces
							}
						]"
					/>
				</a-form-item>
				<a-form-item label="状态">
					<a-radio-group v-decorator="['status', { initialValue: '0', rules: [{ required: true, message: '请选择状态' }] }]">
						<a-radio value="0">启用</a-radio>
						<a-radio value="1">停用</a-radio>
					</a-radio-group>
				</a-form-item>
				<a-form-item label="排序号" extra="数据越小越靠前">
					<a-input-number class="w100" :min="0" :precision="0" placeholder="排序号" v-decorator="['roleSort']" />
				</a-form-item>
				<a-form-item label="备注">
					<a-textarea
						placeholder="备注"
						v-decorator="[
							'remark',
							{
								rules: [{ max: 200, message: '备注不超过200个字符' }]
							}
						]"
					/>
				</a-form-item>
			</a-form>
		</a-spin>
	</globalModal>
</template>
<script>
import { ModalMixins } from '@/mixins';
import { sysManageapi } from '@/api/index.js';
export default {
	name: 'addOrEditRoleModal',
	data() {
		return {
			orgList: []
		};
	},
	mixins: [ModalMixins],
	created() {},
	methods: {
		getDefaultList() {
			if (this.isAdmin && this.orgList.length == 0) {
				this.getAllOrgList();
			}
		},
		getAllOrgList() {
			this.$postAction(sysManageapi.orgUrl.getAllList).then(res => {
				if (res && res.code == 1) {
					this.orgList = res.data;
				}
			});
		}
	}
};
</script>

<style scoped></style>
